<%--
  Created by IntelliJ IDEA.
  User: gaosubo
  Date: 2020/9/12
  Time: 18:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>成果审核  主任</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/lib/layui/layui/css/layui.css"/>
    <script type="text/javascript" src="/js/news/jquery-1.9.1.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/jquery/jquery.cookie.js"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/js/common/fileupload.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.all.js"></script>
</head>
<style>
    .btn {
        text-align: right;
    }
    .layui-form-item {
        margin-bottom: 5px;
    }
    .layui-input-inline{
        width: 300px !important;
    }
    .layui-icon-ok{
        margin-top: 6px;
    }
    .item{
        line-height: 30px;
        margin-top: 9px;
        margin: 8px;
        margin-left: 20px;
    }
</style>
<body>
<div>
    <div class="item"><span style="font-size: 22px;display: inline-block;vertical-align: middle;">成果审核(主任)</span>
    </div>
    <hr class="layui-bg-blue">
    <div>
        <div class="btn">
            <div style="margin-left: 10px;float: left" class="layui-form">
                <input type="radio" checked name="trStatus" value='1' lay-filter="status" value="" title="未审核">
                <input type="radio" name="trStatus" value='2' lay-filter="status" value="" title="通过">
                <input type="radio" name="trStatus" value="3"  lay-filter="status" title="退回">
                <input type="radio" name="trStatus" value="4"  lay-filter="status" title="不通过">
            </div>
            <div>
                <a href="/Recognize/getProjectList?trStatus=2&trType=15&isExport=true&deptName=1" type="button" class="layui-btn immp layui-btn-sm " id="del" style="margin-right: 15px" >
                    <i class="layui-icon">&#xe601;</i>
                    导出
                </a>
            </div>
        </div>
    </div>
    <div>
        <table class="layui-hide" id="test" lay-filter="test"></table>
    </div>
</div>

</body>
</html>
<script type="text/html" id="barDemo">
    {{#  if( d.trStatus == '1' ){ }}
        <a class="layui-btn layui-btn-xs" lay-event="edit">审核</a>
    {{#  } }}
    <a class="layui-btn layui-btn-xs" lay-event="select">查看</a>
</script>
<script>

    //判断是否为空
    function esName(name){
        if (name!=undefined){
            return name;
        }
        return '';
    }

    //判断类型是否存在
    function isRemarks( remarks , trType){
        for (var i = 0; i < remarks.length; i++) {
            if (remarks[i].trType == trType){
                return remarks[i];
            }
        }
        return '';
    }

    layui.use(['table', 'layer', 'form','laydate','upload'], function () {
        var table = layui.table
            , layer = layui.layer
            , form = layui.form
            , upload = layui.upload
            , laydate = layui.laydate
        $(document).ready(function(){
            form.render();
        });
        var tableInt = table.render({
            elem: '#test'
            ,url:'/Recognize/getProjectList'
            ,where:{
                trStatus:1,
                trType:15,
                useFlag:true,
                deptName : '同部门'
            }
            ,parseData: function(res){
                return {
                    "code":0,
                    "data": res.object,
                    "count": res.totleNum,
                };
            }
            , cols: [[
                {type: 'checkbox'},
                {field: 'planName', title: '任务名称', align: 'center',templet: function(d){
                        return esName(d.rpmPlan.planName);
                    }}
                , {field: 'topicName', title: '成果名称', align: 'center',templet: function(d){
                        return esName(d.rpmTopic.topicName);
                    }}
                , {field: 'topicTypeName', title: '成果类型', align: 'center',templet: function(d){
                        return esName(d.rpmTopic.topicTypeName);
                    }}
                , {field: 'userName', title: '申报人姓名', align: 'center',templet: function(d){
                        return esName(d.rpmTopic.userName);
                    }}
                , {field: 'deptName', title: '科室', align: 'center',templet: function(d){
                        return esName(d.rpmTopic.deptName);
                    }}
                , {field: 'state', title: '申报状态', align: 'center',templet: function(d){
                        if(d.rpmPlan.state == '1'){
                            return '申报中';
                        }else{
                            return '申报结束';
                        }
                        return '';
                    }}
               /* , {title: '院学术委员会秘书处意见', align: 'center',templet: function(d){
                        var remark16 = isRemarks(d.rpmTopic.remarkList , '16');
                        if( remark16 != '' ){
                            return remark16['trRemark'];
                        }
                        return '';
                    }}*/
                , {field: 'type', title: '操作', toolbar: '#barDemo'}
            ]],
            page:true
        });


        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            var remarkList = data.rpmTopic.remarkList;


            if(obj.event === 'edit'){
                layer.open({
                    type: 1,
                    title:'审核',
                    btn: ['确定', '返回'],
                    area: ['30%', '40%'],
                    content: '<div id="cont" style="margin: 10px">\n' +
                        '        <form class="layui-form" action="" id="ajaxforms" lay-filter="ajaxforms">\n' +
                        '            <div class="layui-form-item">\n' +
                        '                <div class="layui-inline">\n' +
                        '                    <div class="layui-form-item layui-form-text">\n' +
                        '                        <label class="layui-form-label">审核意见:</label>\n' +
                        '                        <div class="layui-input-inline">\n' +
                        '                            <textarea placeholder="请输入内容" class="layui-textarea trRemark"  name="trRemark"></textarea>\n' +
                        '                        </div>\n' +
                        '                    </div>\n' +
                        '                </div>\n' +
                        '            </div>\n' +
                        ' <div class="layui-form-item">\n' +
                        '    <label class="layui-form-label">状态:</label>\n' +
                        '    <div class="layui-input-block states">\n' +
                        '      <input type="radio" name="trStatus" value="2" title="通过" checked>\n' +
                        '      <input type="radio" name="trStatus" value="3" title="回退">\n' +
                        '      <input type="radio" name="trStatus" value="4" title="不通过">\n' +
                        '    </div>\n' +
                        '  </div>'+
                        '        </form>\n' +
                        '    </div>',
                    success:function (res) {
                        form.render();
                    },
                    yes:function (res) {
                        var trStatus = $('.states input[name="trStatus"]:checked').val();
                        var trRemark = $('.trRemark').val();
                        var arr = [
                            {
                                trId:data.trId,
                                trStatus:trStatus,
                                trRemark:trRemark,
                            }
                        ];

                        //判断是否有  秘书处的审批
                        if (  trStatus == '2' ) {
                           var obj2 = {
                               trId:function () {
                                   var index = remarkList.findIndex( b => { return b.trType === '16' } );
                                   return index != -1 ? remarkList[index].trId : '';
                               }(),
                               trType: '16',
                               trStatus: '1',
                               trTopicId: data.trTopicId,
                               trPlanId: data.rpmPlan.planId,
                           }
                            arr.push(obj2);
                        }

                        $.ajax({
                            url:'/Recognize/updateRecogizeRemark',
                            dataType: 'json',
                            type: 'post',
                            data:{
                                trJson : JSON.stringify(arr)
                            },
                            success:function (res) {
                                if (res.flag) {
                                    layer.msg('审核成功！', {icon: 1});
                                    tableInt.reload()
                                    layer.closeAll();
                                }
                            }
                        })
                    }
                })
            }else if(obj.event === 'select') {
                layer.open({
                    type: 2,
                    title:'查看',
                    btn: ['返回'],
                    area: ['70%', '85%'],
                    content: '/Results/declaration?type=1&planId=' + data.rpmPlan.planId + '&topicId=' + data.rpmTopic.topicId+'&edit=0',
                    yes:function (index, layero) {
                        layer.close(index);
                    }
                })
            }
        });

        //监听顶部单选按钮
        form.on('radio(status)', function(data){
            var value = data.value;
            table.reload('test', {
                where:{
                    trStatus:value
                }
            });
        });


    })



</script>
